package com.sh.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sh.dao.TeacherDao;
import com.sh.entity.Teacher;
import com.sh.util.Result;

@RestController
public class TeacherController {
	@Autowired
	private TeacherDao teacherDao;

	@RequestMapping("/selectTeacher")
	public Result getAll(Integer limit, Integer page, Teacher teacher, Map<String, Object> map) {
		map.put("page", (page - 1) * limit);
		map.put("limit", limit);
		map.put("tName", teacher.gettName());
		map.put("tCard", teacher.gettCard()); // 存取页数和前台传来的数据
		List<Map<String, Object>> getAlList = teacherDao.getAll(map);
		Integer getInteger = teacherDao.getCount();
		Result result = new Result(true, 0, null, getInteger, getAlList);
		return result;
	}

	// 添加
	@RequestMapping("/insertTeacher")
	public Result getadd(Teacher teacher) {
		int inserts = teacherDao.insertTeacher(teacher);
		Result res = new Result(200, "", inserts, true);
		return res;
	}

	// 修改
	@RequestMapping("/updateTeacher")
	public Result updateTeacher(Teacher teacher) {
		Integer updates = teacherDao.updateTeacher(teacher);
		Result res = new Result(200, "", updates, true);
		return res;
	}

	// 删除
	@RequestMapping("/deleteTeacher")
	public Result deleteTeacher(Integer tid) {
		int i = teacherDao.deleteTeacher(tid);
		Result res = new Result(200, "", i, true);
		return res;

	}

}
